package object3D;

import context.*;

import geometry3D.Point3D;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D;
import java.awt.geom.GeneralPath;



// ***************************************************************************
// *** CLASS: KjellerTrapp
// ***************************************************************************
public class KjellerTrapp extends Block implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  public static final Color murFarge=Color.lightGray;

  public static final double oppTrinn=0.18;
  public static final double innTrinn=0.25;
  
  public KjellerTrapp(String ident,Point3D p0,double width,double height,double depth)
  { super(ident,p0,width,height,depth);
  }
    
  // ***************************************************************************
  // *** METHOD: getModel3D
  // ***************************************************************************
//  public /*abstract*/ Group getModel3D(Appearance appearance)
//  { Group tg=new Group();
//    tg.addChild(trinn1.getModel3D(appearance));
//    tg.addChild(trinn2.getModel3D(appearance));
//    tg.addChild(trinn3.getModel3D(appearance));
//    tg.addChild(trinn4.getModel3D(appearance));
//    tg.addChild(trinn5.getModel3D(appearance));
//    return(tg);
//  }  


  public void drawProjection(int direction,Graphics2D g,Point2D.Double origo2D,double scale,Color c)
  {

    Rectangle2D.Double r=projection(direction,origo2D,scale);
    switch(direction)
    {
      case NORTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case SOUTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case EAST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case WEST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
//      case ABOVE: drawProjectionAbove(g,r,scale,c); break;
//      case BELOW: drawProjectionBelow(g,r,scale,c); break;
//      case VCUT: drawVerticalCut(g,r,scale,c); break;
      case HCUT: tegnTrappPlan(g,r,origo2D,scale,c); break;
      default: super.drawProjection(direction,g,origo2D,scale,c);
    }  
  }

  private void tegnTrapp(int direction,Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
  }

  private void tegnTrappPlan(Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
    double yn=r.y;
    double n1=r.x;
    double n2=n1+0.40*scale;
    double n3=n2+0.40*scale;
    double n4=n3+0.27*scale;
    double n5=n4+0.26*scale;
    double n6=n5+0.27*scale;
    double n7=n6+0.30*scale;
    double n8=n7+0.40*scale;
    
    double xe=r.x+r.width;
    double e1=r.y+0.30*scale;
    double e2=e1+0.30*scale;
    double e3=e2+0.30*scale;
    
    double ss=r.x+0.90*scale;
    
    double ys=r.y+0.85*scale;
    double s1=ss;
    double s2=ss;
    double s3=ss;
    double s4=s3+0.20*scale;
    double s5=s4+0.20*scale;
    double s6=s5+0.20*scale;
    double s7=s6+0.20*scale;
    double s8=s7;
    double s9=s7;
    double s10=s7;
    double s11=s7;

    double d1=0.05*scale/2;
    double d2=0.05*scale/4;
    
    line(g,n1,yn,n8,yn);
    
    line(g,n1,yn,s1,ys+2*d1);
    line(g,n2,yn,s2,ys+d1);
    line(g,n3,yn,s3,ys);
    line(g,n4,yn,s4,ys);
    line(g,n5,yn,s5,ys);
    line(g,n6,yn,s6,ys);
    line(g,n7,yn,s7,ys);
    line(g,n8,yn,s8,ys+d2);
    line(g,xe,e1,s9,ys+2*d2);
    line(g,xe,e2,s10,ys+3*d2);
    line(g,xe,e3,s11,ys+4*d2);
    
    // Tegn Rekkverk
    Rectangle2D.Double rekkverk=new Rectangle2D.Double(ss,ys,0.80*scale,0.05*scale);
    g.draw(rekkverk);
    
    // Tegn Pil
    double x0=r.x+0.90*scale;
    double y0=r.y+0.425*scale;
    double xT=x0+0.80*scale;
    double dx=0.20*scale;
    double dy=0.15*scale;    
    line(g,x0,y0,xT,y0);
    line(g,xT,y0,xT-dx,y0+dy);
    line(g,xT,y0,xT-dx,y0-dy);
  }
  
  
  private void line(Graphics2D g,double x1,double y1,double x2,double y2)
  { g.draw(new Line2D.Double(x1,y1,x2,y2)); }

}
